package servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import Model.*;
import DAO.DAOException;
import DAO.MySQL.*;

public class AddNewProduct extends HttpServlet {
   
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        int productnum=Integer.parseInt(request.getParameter("productname"));
        String productname=request.getParameter("productname");
        double unitprice=Double.parseDouble(request.getParameter("unitprice"));
        String description=request.getParameter("description");
        String color=request.getParameter("color");
        String dimension=request.getParameter("dimension");
        String manufacturer=request.getParameter("manufacturer");
        int reorderlevel=Integer.parseInt(request.getParameter("reorderlevel"));
        int minorder=Integer.parseInt(request.getParameter("minorder"));
        String shelflocation=request.getParameter("shelflocation");
        int instock=Integer.parseInt(request.getParameter("instock"));
        Product p=new Product();
      
        p.setColor(color);
        p.setDescription(description);
        p.setDimension(dimension);
        p.setInstock(instock);
        p.setManufacturer(manufacturer);
        p.setMinorder(minorder);
        p.setProductname(productname);
        p.setProductnum(productnum);
        p.setReorderlevel(reorderlevel);
        p.setShelflocation(shelflocation);
        p.setUnitprice(unitprice);
        ProductsDAOImpl pi=new ProductsDAOImpl();
        try {
			pi.insertProduct(p);
			request.getRequestDispatcher("ListParts.do").forward(request, response);
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    } 

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

}
